/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SettingsPanel.java
 *
 * Created on 2011-08-11, 19:52:33
 */
package remotechessplayer;

/**
 *
 * @author Jedrek
 */
class SettingsPanel extends javax.swing.JPanel {

    ClientPanel clientPanel;
    ServerPanel serverPanel;
    
    public boolean workAsServer = false;
    
    /** Creates new form SettingsPanel */
    public SettingsPanel() {
        initComponents();
        clientPanel = new ClientPanel(this);
        clientPanel.setSize(pSettingsContainer.getPreferredSize());
        serverPanel = new ServerPanel(this);
        serverPanel.setSize(pSettingsContainer.getPreferredSize());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        WorkAsGroup = new javax.swing.ButtonGroup();
        rbClient = new javax.swing.JRadioButton();
        rbServer = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        pSettingsContainer = new javax.swing.JPanel();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Connection settings"));

        WorkAsGroup.add(rbClient);
        rbClient.setText("Client");
        rbClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbClientActionPerformed(evt);
            }
        });

        WorkAsGroup.add(rbServer);
        rbServer.setText("Server");
        rbServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbServerActionPerformed(evt);
            }
        });

        jLabel1.setText("Work as:");

        pSettingsContainer.setPreferredSize(new java.awt.Dimension(200, 295));

        javax.swing.GroupLayout pSettingsContainerLayout = new javax.swing.GroupLayout(pSettingsContainer);
        pSettingsContainer.setLayout(pSettingsContainerLayout);
        pSettingsContainerLayout.setHorizontalGroup(
            pSettingsContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 199, Short.MAX_VALUE)
        );
        pSettingsContainerLayout.setVerticalGroup(
            pSettingsContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 296, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(rbClient)
                                .addGap(18, 18, 18)
                                .addComponent(rbServer))
                            .addComponent(jLabel1)))
                    .addComponent(pSettingsContainer, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbClient)
                    .addComponent(rbServer))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pSettingsContainer, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void rbClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbClientActionPerformed
        workAsServer = false;
        pSettingsContainer.remove(serverPanel);
        pSettingsContainer.add(clientPanel);
        pSettingsContainer.validate();
        clientPanel.validate();
        validate();
        repaint();
    }//GEN-LAST:event_rbClientActionPerformed

    private void rbServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbServerActionPerformed
        workAsServer = true;
        pSettingsContainer.remove(clientPanel);
        pSettingsContainer.add(serverPanel);
        pSettingsContainer.validate();
        serverPanel.validate();
        validate();
        repaint();
    }//GEN-LAST:event_rbServerActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup WorkAsGroup;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JPanel pSettingsContainer;
    public javax.swing.JRadioButton rbClient;
    public javax.swing.JRadioButton rbServer;
    // End of variables declaration//GEN-END:variables
}
